<?php
 require("../inc/sku.php");
 
  if(isset($_POST['edit']))
  {
  	if($_POST['edit'] === '1')
	{
		$results = editSKU($_POST);
		
		header("location:index.php");
	}
  }
 
  $results = getSKU($_GET['id']);
  
  $price_results = priceHistory($_GET['id']);
  
  $vendors = getVendors();
  
  $row = $results->fetch_assoc();
?>
<!DOCTYPE html>
    <html>
    <head>
        <meta charset="utf-8" />
        <title><?=$title ?> Edit Product Information</title>
         <? require('../inc/header-info.php'); ?>
    </head>
    <body>
        <div class="container">
            <? include('../inc/nav.php'); ?>
             <form name="form1" method="post" action="edit.php">
             	<h4>Edit Product Information</h4>
             	<input type="hidden" name="edit" value='1'> 
            	<input type="hidden" name="id" value='<?=$row['id']?>'>
            		<label class="control-label">Vendor</label>
    				<div class="controls">
    					<select name='Vendor_id'>
    						<option value='<?=$row['vendor_id']?>'><?=$row['vendor']?></option>	
    						<? while($row_vend = $vendors->fetch_assoc()): ?>
    							<option value='<?=$row_vend['id']?>'><?=$row_vend['name']?></option>					
                    		<? endwhile; ?>
							
						</select>
    				</div>			
            
					<label class="control-label" for="product_name">Product Name:</label>
					<div class="controls">
						<input type="text" id="product_name" name="product_name" placeholder="Product Name" <? if($row['product_name']){ echo "value='$row[product_name]'";} ?>>
					</div>
					
    			
					<label class="control-label" for="description">Product Description:</label>
					<div class="controls">
						<input type="text" id="description"  name="description" placeholder="Product Description" <? if($row['description']){ echo "value='$row[description]'";} ?>>
					</div>
				
				
					<label class="control-label" for="weight">Product Weight:</label>
					<div class="controls">
						<input type="text" id="weight" name="weight" placeholder="Product Weight" <? if($row['weight']){ echo "value='$row[weight]'";} ?>>
					</div>
            	<div class="form-actions">
  					<button type="submit" class="btn btn-primary">Edit Product</button>
					<a href="<?=$url?>sku/index.php"><button class="btn" type="button">Cancel</button></a>
				</div>
            </form> 
            <h4>Price History Information for SKU: <?=$row['id']?></h4>
            <table class="table">
    			<thead>
    				<tr>
    					<th>Price</th>
    					<th>Date</th>
    				</tr>
    			</thead>
    			<tbody>
    				<? while($row = $price_results->fetch_assoc()): ?>
    					<tr>
							<td><?=$row['price']?></td>
							<td><?=$row['date']?></td>
                        </tr>
                    <? endwhile; ?>

    			</tbody>
    		</table>
   	  		<form class="form-search" name="newPrice" method="post" action="prices.php">
  				<div class="input-append">
  				<input type="hidden" name="EnterPrice" value='1'>
  			    <input type="hidden" name="sku" value='<?=$_GET['id']?>'>
    			<input type="number" name="newPrice" class="span2 search-query" placeholder="New Price">
    			<button type="submit" class="btn">Price Change</button>
  				</div>
  			</form>
            
		</div>
	</body>
</html>
